package 程序员面试金典;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class 可互换矩形的数组 {

    public long interchangeableRectangles(int[][] rectangles) {
        Map<Double, Integer> map = new HashMap<>();
        int m=rectangles.length;
        for (int i = 0; i < m; i++) {
            double num =(double) rectangles[i][0] / rectangles[i][1];
            map.put(num,map.getOrDefault(num,0)+1);
        }
        long res=0;
        for (int i = 0; i < m; i++) {
            double num =(double) rectangles[i][0] / rectangles[i][1];
            res+=(map.get(num)-1);
        }
        return res/2;
    }
    public long interchangeableRectangles1(int[][] rectangles) {
         int m=rectangles.length;
         int n=rectangles[0].length;
         if (m==0)
             return 0;
         long res=0;
        for (int i = 0; i < m-1; i++) {
            for (int j = i+1; j < m; j++) {
                double i1 =(double) rectangles[i][0] / rectangles[i][1];
                double i2 =(double) rectangles[j][0] / rectangles[j][1];
                if (i1==i2)
                    res++;
            }
        }
        return res;
    }
    @Test
    public void test(){
        int m=3;
        int n=2;
        System.out.println((double)m/n);
    }
}
